<%--
  Created by IntelliJ IDEA.
  User: Mac
  Date: 2017/8/7
  Time: 12:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>实习变更申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/global.css">
</head>
<body>
<div style="width: 50%;height: 100%;overflow:scroll;float: left">
    <fieldset class="layui-elem-field">
        <legend>目前实习信息</legend>
        <form id="contentNow" class="layui-form" action="" method="">
            <div class="layui-form-item">
                <label class="layui-form-label">用人单位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="org" v-model="orgInfo.fullname" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习岗位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="position" v-model="internInfo.position" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">岗位介绍</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="jobintro" disabled>{{ internInfo.jobintro }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习内容</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" disabled>{{ internInfo.jobcontent }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习成果</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" value="" disabled>{{ internInfo.outcome }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">办公环境</label>
                <img id="nowWorkPic" style="height: 100px;width: 100px" disabled>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习单位指导老师</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructor" v-model="internInfo.instructor" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单位老师联系电话</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructorphone" v-model="internInfo.instructorphone" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审核意见</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="auditsug" disabled>{{ internInfo.auditsug }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="startTime" v-model="getYearMonthDate(internInfo.start)" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="endTime" v-model="getYearMonthDate(internInfo.end)" disabled>
                </div>
            </div>
        </form>
    </fieldset>
</div>
<div style="width: 50%;height: 100%;overflow:scroll;float: right">
    <fieldset class="layui-elem-field">
        <legend>新申请实习信息</legend>
        <form id="contentWant" class="layui-form" action="" method="">
            <div class="layui-form-item">
                <label class="layui-form-label">用人单位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="org" v-model="orgInfo.fullname" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习岗位</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="position" v-model="internInfo.position" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">岗位介绍</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="jobintro" disabled>{{ internInfo.jobintro }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习内容</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" disabled>{{ internInfo.jobcontent }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习成果</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" value="" disabled>{{ internInfo.outcome }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">办公环境</label>
                <img id="futureWorkPic" style="height: 100px;width: 100px" disabled>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">实习单位指导老师</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructor" v-model="internInfo.instructor" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单位老师联系电话</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="instructorphone" v-model="internInfo.instructorphone" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审核意见</label>
                <div class="layui-input-inline">
                    <textarea class="layui-input" name="auditsug" disabled>{{ internInfo.auditsug }}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="startTime" v-model="getYearMonthDate(internInfo.start)" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="endTime" v-model="getYearMonthDate(internInfo.end)" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" class="layui-btn" lay-filter="pass" value="审核通过" lay-submit>
                    <input type="button" class="layui-btn" lay-filter="reject" value="审核不通过" lay-submit>
                    <input type="button" class="layui-btn layui-btn-primary" @click="reload" value="返回">
                </div>
            </div>
        </form>
    </fieldset>
</div>
<script type="text/javascript" src="../../static/common/layui/layui.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=8K08Q6AWX7LcrskmDiE6BFSG5LqUfGGE"></script>
<script src="../../static/common/vue.min.js"></script>
<script src="../../static/common/axios.min.js"></script>
<script>
    var studentInfoId = <%=request.getParameter("studentInfoId")%>;
    var studentUserId = <%=request.getParameter("studentUserId")%>;
    var studentInfo = {};
    //    console.log(studentInfoId);
    /**
     * 时间格式取年月日
     * @param time
     * @returns {*}
     */
    function getYearMonthDate(time) {
//        console.log(time);
        if(time!=null) {
            var YMD = time.split(" ")[0];  // 年月日
            var HMS = time.split(" ")[1];  // 时分秒
            return YMD;
        }
        return null;
    }
    layui.use(['form','jquery','layer'],function () {
        var form = layui.form(),
            $ = layui.jquery,
            layer = layui.layer,
            image = {};
        var vmNow = new Vue({
            el:'#contentNow',
            data:{
                internInfo:{
                    sno:studentInfoId
                },
                orgInfo:{},
                imag:{}
            },
            methods:{
                /**
                 * 得到目前实习信息
                 */
                getInfo:function () {
                    axios.post('/internInfo/findByCondition',{sno:studentInfoId,orgattr:2})
                        .then(function (response) {
//                        console.log(response.data);
                            $('#nowWorkPic').attr('src','');
                            vmNow.internInfo = response.data.data[0].internInfo;
                            vmNow.orgInfo = response.data.data[0].orgInfo;
                            if(response.data.data[0].imag!=null) {
                                vmNow.img = response.data.data[0].imag;
                                $('#nowWorkPic').attr('src',vmNow.img.path);
                            }
//                        console.log(vmNow.internInfo);
//                        console.log(vmNow.orgInfo);
                        })
                        .catch(function (msg) {
                            console.log(msg);
                        })
                }
            }
        });
        vmNow.getInfo();

        var vmWant = new Vue({
            el:'#contentWant',
            data:{
                internInfo:{
                    sno:studentInfoId
                },
                orgInfo:{},
                imag:{}
            },
            methods:{
                /**
                 * 得到新申请的实习信息
                 */
                getInfo:function () {
                    axios.post('/internInfo/findByCondition',{sno:studentInfoId,orgattr:3})
                        .then(function (response) {
//                        console.log(response.data);
                            vmWant.internInfo = response.data.data[0].internInfo;
                            vmWant.orgInfo = response.data.data[0].orgInfo;
                            $('#futureWorkPic').attr('src','');
                            if(response.data.data[0].imag!=null) {
                                vmWant.img = response.data.data[0].imag;
                                $('#futureWorkPic').attr('src',vmWant.img.path);
                            }
//                        console.log(vmWant.internInfo);
//                        console.log(vmWant.orgInfo);
                        })
                        .catch(function (msg) {
                            console.log(msg);
                        })
                },
                /**
                 * 返回按钮
                 */
                reload:function () {
                    console.log("返回");
                    location.href="/teacher/internLists";
                }
            }
        });
        vmWant.getInfo();

        axios.get('/student/findDetail/'+studentUserId)
            .then(function (response) {
                console.log(response.data);
                studentInfo = response.data.data.studentInfo;
                console.log(studentInfo);
            })
            .catch(function (msg) {
                console.log(msg);
            });

        /**
         * 监听审核通过
         */
        form.on('submit(pass)',function (data) {
            console.log(123);
            studentInfo.state = 3;      // 实习中
            vmNow.internInfo.orgattr = 1; // 以前实习的单位
            vmWant.internInfo.orgattr = 2; // 现在实习的单位
            vmWant.internInfo.state = 5; // 行政审核通过

            // 更新一条实习信息
            axios.post('/internInfo/modify',vmWant.internInfo)
                .then(function (response) {
                    if(response.data.success) {
                        layer.msg("操作成功", {icon: 1, time: 1500});
                    }
                    console.log("修改实习记录成功");
                })
                .catch(function (msg) {
                    console.log(msg)
                });
        axios.post('/internInfo/modify',vmNow.internInfo)
            .then(function (response) {

            })
            .catch(function (msg) {
                console.log(msg);
            });
            // 更新学生信息表（最好用findById接口）
        axios.post('/student/modify',studentInfo)
            .then(function (response) {

            })
            .catch(function (msg) {
                console.log(msg);
            });

        });
        /**
         * 监听审核不通过
         */
        form.on('submit(reject)',function (data) {
            console.log(456);
            studentInfo.state = 3;      // 实习中
            vmWant.internInfo.state = 6;    // 行政审核不通过

            // 更新一条实习记录
            axios.post('/internInfo/modify',vmWant.internInfo)
                .then(function (response) {
                    console.log("修改实习记录成功");
                })
                .catch(function (msg) {
                    console.log(msg);
                });
            // 更新学生信息表实习状态恢复为-3-实习中
            axios.post('/student/modify',studentInfo)
                .then(function (response) {
                    console.log("修改学生信息表成功");
                })
                .catch(function (msg) {
                    console.log(msg);
                })
        });
    })
</script>
</body>
</html>